/*
 *  Copyright 2020-2025 the original author or authors.
 *  You cannot use this file unless authorized by the author.
 */

package org.ipig.messaging.rocket.consumer;

import com.alibaba.rocketmq.common.message.MessageExt;
import org.ipig.commons.codec.CodecService;
import org.ipig.commons.codec.kryo.GenericKryoCodec;
import org.ipig.commons.service.ProcessorService;
import org.ipig.constants.ResultStatus;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * 业务消费测试服务实现
 *
 * @author <a href="mailto:comchnts@163.com">chinats</a>
 * @version $$Id$$
 * @since 1.0
 */
@Component
public class GenericProcessorServiceImpl implements ProcessorService<List<MessageExt>, ResultStatus> {
    /*** mq编码 ***/
    @Resource(type = GenericKryoCodec.class)
    protected CodecService gkc;

    @Override
    public ResultStatus process(List<MessageExt> msgs) {
        if (msgs != null && !msgs.isEmpty()) {
            for (MessageExt msg : msgs) {
                String str = null;
                try {
                    str = gkc.decode(msg.getBody(), String.class);
                    System.out.println("消费成功" + str);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return ResultStatus.SUCCESS;
    }
}